package com.vilen.learn.java7.V4.V4_3;

import com.vilen.learn.java7.V4.Author;
import com.vilen.learn.java7.V4.SimpleMicroBlogNode;
import com.vilen.learn.java7.V4.Update;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 并不能运行
 * Created by vilen on 2017/10/2.
 */
//public class ExampleTimingNode implements SimpleMicroBlogNode {
public class ExampleTimingNode{
    private static Update getUpdate(String s) {
        Update.Builder b = new Update.Builder();
        b.updateText(s).author(new Author("Ben"));
        return b.build();
    }

    private final String identifier;
    private final Map<Update, Long> arrivalTime = new ConcurrentHashMap<>();

    public ExampleTimingNode(String identifier) {
        this.identifier = identifier;
    }


    public void propagateUpdate(Update upd_) {
        long currentTime = System.currentTimeMillis();
        System.out.println(currentTime);
        arrivalTime.put(upd_, currentTime);
    }


    public boolean confirmUpdate(Update update_) {
        Long timeRecvd = arrivalTime.get(update_);
        return arrivalTime.get(update_) != null;
    }

    public String getIdent() {
        return identifier;
    }

}
